'''================================for in循环=================================='''

# 左下三角
for i in range(1, 10):
    for j in range(1, i + 1):
        print("{}*{}={:<4d}".format(j, i, j * i), end="")
    print("")
print("=" * 80)

# =====================================================
# 左上三角
for i in range(9, 0, -1):
    for j in range(1, i + 1):
        print("{}*{}={:<4d}".format(j, i, j * i), end="")
    print("")
print("=" * 80)

# =====================================================
# 右下三角
for i in range(1, 10):
    for j in range(1, 10 - i):
        print(end="        ")  # 将左上三角用空格符设置成空白，每个算式后的空格共占8个字节，所以空出的地方输出8个空格符。
    for k in range(i, 0, -1):
        print("{}*{}={:<4d}".format(k, i, k * i), end="")
    print("")
print("=" * 80)

# =====================================================
# 右上三角
for i in range(9, 0, -1):
    for j in range(9, i, -1):
        print(end="        ")  # 将左下三角用空格符设置成空白
    for k in range(i, 0, -1):
        print("{}*{}={:<4d}".format(k, i, k * i), end="")
    print("")
print("=" * 80)

# =====================================================

'''===================================while循环=========================================='''

# 左下三角
i = 1
while i <= 9:
    j = 1
    while j <= i:
        print("{}*{}={:<4d}".format(j, i, j * i), end="")
        j += 1
    print("")
    i += 1
print("=" * 80)

# =====================================================
# 左上三角
i = 9
while i >= 1:
    j = 1
    while j <= i:
        print("{}*{}={:<4d}".format(j, i, j * i), end="")
        j += 1
    print("")
    i -= 1
print("=" * 80)

# =====================================================
# 右下三角
i = 1
while i <= 9:
    k = 9
    while k > i:
        print("        ", end="")
        k -= 1
    j = i
    while j >= 1:
        print("{}*{}={:<4d}".format(j, i, j * i), end="")
        j -= 1
    print("")
    i += 1
print("=" * 80)

# =====================================================
# 右上三角
i = 9
while i >= 1:
    k = i
    while k < 9:
        print("        ", end="")
        k += 1
    j = i
    while j >= 1:
        print("{}*{}={:<4d}".format(j, i, j * i), end="")
        j -= 1
    print("")
    i -= 1
